<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"  >
<head>
    <th:block th:include="include :: header('用户详情')" />
    <th:block th:include="include :: select2-css" />
    <link href="../../../static/css/tax/userDetail.css"   th:href="@{/css/tax/userDetail.css}" rel="stylesheet"/>

</head>
<body class="white-bg">

<div  th:object="${companyInfoModel}" >

    <div class="row-content" style="margin-top: 30px;">
        <span  class="title">ID</span>
        <span  class="content" th:text="*{userid}">1</span>
    </div>
    <div  class="line"></div>


    <div class="row-content">
        <span  class="title">企业名称</span>
        <span  class="content" th:text="*{compname}">******公司</span>
    </div>
    <div  class="line"></div>

    <div class="row-content">
        <span  class="title">统一社会信用代码</span>
        <span  class="content" th:text="*{socialcreditcode}" >12456465465456456</span>
    </div>
    <div  class="line"></div>

    <div class="row-content">
        <span  class="title">行业</span>
        <span  class="content" id="industry-content" th:text=" *{industryname1} +' | ' + *{industryname2}+' | ' + *{industryname3}+' | ' + *{industryname4}">房地产 | 房地产 | 房地产 | 房地产</span>
        <span  id="industry-editBtn" class="editButton"   onclick="editIndustry()"  shiro:hasPermission="tax:user:edit"></span>
        <!--行业修改隐藏选择框-->
        <span id="industry-select"  class="editContent"  hidden >
            <form action="#">

                <!--        一级行业选择        -->
                <select id="industryL1"  class="select"  onchange="selectIndustryL1()">
                    <option>--请选择--</option>
                </select>

                <!--        二级行业选择         -->
                <select id="industryL2"  class="select" onchange="selectIndustryL2()">
                    <option>--请选择--</option>
                </select>

                <!--        三级行业选择         -->
                <select id="industryL3"  class="select" onchange="selectIndustryL3()">
                    <option>--请选择--</option>
                </select>

                <!--        四级行业选择         -->
                <select id="industryL4" class="select" onchange="selectIndustryL4()">
                    <option>--请选择--</option>
                </select>

                <button type="button"  onClick="saveIndustry()"  class="saveButton" >保存</button>
            </form>
        </span>

    </div>
    <div  class="line"></div>

    <div class="row-content">
        <span  class="title">行政区划</span>
        <span  id="region-content" class="content" th:text="*{province} +' | ' + *{city}+' | ' + *{district}"  >北京 | 北京 | 朝阳区</span>

        <span  id="region-editBtn" class="editButton"  onclick="editRegion()" shiro:hasPermission="tax:user:edit"></span>

        <span id="region-select"  class="editContent"  hidden >
            <form action="#">

                <!--        省份选择        -->
                <select id="prov"  class="select"  onchange="selectProvince()">
                    <option>--请选择--</option>
                </select>

                <!--        城市选择        -->
                <select id="city"  class="select"  onchange="selectCity()">
                    <option>--请选择--</option>
                </select>

                <!--        区县选择        -->
                <select id="country" class="select" onchange="selecCountry()">
                    <option>--请选择--</option>
                </select>

                <button type="button"  class="saveButton"  onClick="saveRegionModifyAddr()"  >保存</button>
            </form>
        </span>



    </div>
    <div  class="line"></div>

    <div class="row-content">
        <span  class="title">超级管理员</span>

        <span  id="admin-content" class="content" th:text="*{username}">18699998888</span>
        <span  id="admin-editBtn" class="editButton" onclick="editAdminUser()" shiro:hasPermission="tax:user:edit"></span>
        <span id="newAdminUser"  hidden class="editContent" >
            <form action="#">
                <input id="usernameInput" type="text" placeholder="请输入手机号" maxlength="11" name="phonenumber" autocomplete="off"  required>

                <button type="button" onClick="saveNewAdminUser()"  class="saveButton"   >保存</button>
            </form>
        </span>
    </div>
    <div  class="line"></div>


    <div class="row-content">
        <span  class="title">注册时间</span>
        <span  class="content" th:text="*{createtime}" >2019年10月1日</span>
    </div>
    <div  class="line"></div>


    <div class="row-content">
        <span  class="title">产品类型</span>
        <span  id="productType-content" class="content" th:text="*{type}">多企业10家</span>
        <span  id="productType-editBtn" class="editButton" onclick="editProductType()" shiro:hasPermission="tax:user:edit"></span>

        <span id="newProductType"  class="editContent"  hidden >
            <form action="#">

                <!--        产品类型选择        -->
                <select  id="productTypeSelect" class="select"  onchange="selectProductType()">
                    <option>多企业10家</option>
                    <option>无限制</option>
                    <option>一家公司</option>

                </select>

                <button type="button"  onClick="saveProductType()"   class="saveButton" >保存</button>
            </form>
        </span>

    </div>
    <div  class="line"></div>

    <div class="row-content">
        <span   class="title">到期时间</span>
        <span   id="dueDate-content"  class="content" th:text="*{createtime}">2020年9月30日</span>
        <span   id="dueDate-editBtn" class="editButton" onclick="editDeuDate()" shiro:hasPermission="tax:user:edit"></span>

        <span id="newDueDate"  hidden  class="editContent">
            <form action="#">
                <input type="date"  id="dueDateInput"/>
                <button type="button" onClick="saveNewDueDate()"  class="saveButton"  >保存</button>
            </form>
        </span>

    </div>
    <div  class="line"></div>

    <div class="row-content">
        <span  class="title">状态</span>
        <span  id="status-content" class="content" th:text="*{userstatus}" >正常</span>
        <span  id="status-editBtn" class="editButton" onclick="editStatus()" shiro:hasPermission="tax:user:edit"></span>

        <span id="newStatus"  class="editContent"  hidden >
            <form action="#">

                <!--        状态选择        -->
                <select  id="statusSelect" class="select"   onchange="selectStatus()">
                    <option>正常</option>
                    <option>禁用</option>
                </select>

                <button type="button"  onClick="saveStatus()"   class="saveButton" >保存</button>
            </form>
        </span>

    </div>
    <div  class="line"></div>




</div>


<!--<script th:src="@{/js/jquery.min.js}"></script>-->
<!--<script th:src="@{/js/bootstrap.min.js}"></script>-->
<!--<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>-->



<!-- 全局js -->
<script src="../../../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../../../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>

<script src="../../../static/ajax/libs/layer/layer.min.js" th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script src="../../../static/ruoyi/js/ry-ui.js" th:src="@{/ruoyi/js/ry-ui.js?v=3.3.0}"></script>


<script type="text/javascript" th:inline="javascript">

    $(function() {

        // var  url = '/tax/selectRegisterUserByID/' + parentCode;
        // var config = {
        //     url: 'http://localhost:8088'+url,
        //     type: 'get',
        //     success: function(result) {
        //         console.log(result);
        //
        //     }
        // };
        // console.log(config);
        // $.ajax(config);
    });

    var infoModel = [[${companyInfoModel}]];
    var  userID = infoModel.userid;
    var  institutionid = infoModel.institutionid ;

    /*根据id获取对象*/
    function getEleById(str) {
        return document.getElementById(str);
    }

    /**
     * 修改行业
     */

    function editIndustry() {
        var industryContent = getEleById('industry-content');
        var  industryEditBtn = getEleById('industry-editBtn');
        var  industrySelect = getEleById('industry-select');
        

        industryContent.style.display= 'none' ;
        industryEditBtn.style.display = 'none' ;
        industrySelect.style.display = 'inline-block' ;
        getIndustryWithCode('-1',1);


    }
    /*点击保存按钮  保存用户所选的行业*/
    function saveIndustry() {

        var industryL1Value =  $("#industryL1").find("option:selected").text();
        var industryL2Value =  $("#industryL2").find("option:selected").text();
        var industryL3Value =  $("#industryL3").find("option:selected").text();
        var industryL4Value =  $("#industryL4").find("option:selected").text();

        if (industryL1Value == '--请选择--' || industryL2Value == '--请选择--' || industryL3Value == '--请选择--' || industryL4Value == '--请选择--' ){
            $.modal.alertError("请选择完整的行业");
            console.log('请选择完整的行业');

        } else {
            var industryContent = getEleById('industry-content');
            var  industryEditBtn = getEleById('industry-editBtn');
            var  industrySelect = getEleById('industry-select');

            industryContent.style.display=  'inline-block'  ;
            industryEditBtn.style.display = 'inline-block'  ;
            industrySelect.style.display =  'none';


            industryContent.innerText = infoModel.industryname1 + ' | ' + infoModel.industryname2 + ' | ' +infoModel.industryname3 + ' | ' +infoModel.industryname4 ;
            infoModel.userid = null;
            infoModel.institutionid = institutionid ;
            updateCompanyInfo(infoModel);
        }


    }



    /**
     * 修改行政区划
     */

    function editRegion() {
        console.log('点击编辑 ---修改行政区划');



        var regionContent = getEleById('region-content');
        var  regionEditBtn = getEleById('region-editBtn');
        var  regionSelect = getEleById('region-select');

        regionContent.style.display= 'none' ;
        regionEditBtn.style.display = 'none' ;
        regionSelect.style.display = 'inline-block' ;

        getRegionWithCode('-1',1);
    }

    /*点击保存按钮  保存用户所选的行政区划*/
    function saveRegionModifyAddr() {



        if (current.prov == '--请选择--' || current.city == '--请选择--' || current.country == '--请选择--' ||
            current.prov == '' || current.city == '' || current.country == ''){
            $.modal.alertError("请选择完整的行政区划");
            console.log('请选择完整的行政区划');

        } else {
            console.log('保存修改的行政区划');

            var regionContent = getEleById('region-content');
            var regionEditBtn = getEleById('region-editBtn');
            var regionSelect = getEleById('region-select');

            regionContent.style.display = 'inline-block';
            regionEditBtn.style.display = 'inline-block';
            regionSelect.style.display = 'none';

            regionContent.innerText = infoModel.province + ' | ' + infoModel.city + ' | ' + infoModel.district;
            infoModel.userid = null;
            infoModel.institutionid = institutionid;
            updateCompanyInfo(infoModel);
        }
    }


    /**
     * 修改超级管理员
     */

    function editAdminUser() {
        var adminContentv = getEleById('admin-content');
        var  adminEditBtn = getEleById('admin-editBtn');
        var  newAdminUser = getEleById('newAdminUser');

        adminContentv.style.display= 'none' ;
        adminEditBtn.style.display = 'none' ;
        newAdminUser.style.display = 'inline-block' ;
    }

    function isTruePhone(str){
        var reg = /^1[34578]\d{9}$/;
        if(!reg.test(str)){
            return false;
        }
        return true;

    }

    function saveNewAdminUser() {

        var userInput = getEleById('usernameInput');
        var  newUser = userInput.value ;

        if (isTruePhone(newUser)) {
            var adminContentv = getEleById('admin-content');
            var  adminEditBtn = getEleById('admin-editBtn');
            var  newAdminUser = getEleById('newAdminUser');

            adminContentv.style.display= 'inline-block'  ;
            adminEditBtn.style.display = 'inline-block';
            newAdminUser.style.display =  'none';




            var adminuser = getEleById('admin-content');
            adminuser.innerText = newUser;

            console.log(newUser);

            infoModel.username = newUser;
            infoModel.userid = userID;
            infoModel.institutionid = null ;
            updateCompanyInfo(infoModel);

        }else {
            $.modal.alertError("请输入正确的手机号码");

        }


    }

    /**
     * 修改产品类型
     */

    function editProductType() {
        var productTypeContent = getEleById('productType-content');
        var  productTypeEditBtn = getEleById('productType-editBtn');
        var  newProductType = getEleById('newProductType');

        productTypeContent.style.display= 'none' ;
        productTypeEditBtn.style.display = 'none' ;
        newProductType.style.display = 'inline-block' ;
    }

    function selectProductType() {
        
    }
    function saveProductType() {
        var productTypeContent = getEleById('productType-content');
        var  productTypeEditBtn = getEleById('productType-editBtn');
        var  newProductType = getEleById('newProductType');

        productTypeContent.style.display= 'inline-block'  ;
        productTypeEditBtn.style.display = 'inline-block';
        newProductType.style.display =  'none';


        var productTypeSelect = getEleById('productTypeSelect');
        var  newProductType = productTypeSelect.value ;

        var productType = getEleById('productType-content');
        productType.innerText = newProductType;

        infoModel.type =  newProductType ;
        infoModel.userid = userID;
        infoModel.institutionid = null ;
        updateCompanyInfo(infoModel);
    }


    /**
     * 修改到期时间
     */

    function editDeuDate() {
        var  dueDateContent = getEleById('dueDate-content');
        var  dueDateEditBtn = getEleById('dueDate-editBtn');
        var  newdueDate = getEleById('newDueDate');

        var dueDateInput = getEleById('dueDateInput');

        // var nowDate = Date();
        // dueDateInput.value = nowDate;

        // 给input  date设置默认值
        var now = new Date();
        //格式化日，如果小于9，前面补0
        var day = ("0" + now.getDate()).slice(-2);
        //格式化月，如果小于9，前面补0
        var month = ("0" + (now.getMonth() + 1)).slice(-2);
        //拼装完整日期格式
        var today = now.getFullYear()+"-"+(month)+"-"+(day) ;
        //完成赋值
        dueDateInput.value =today;


        dueDateContent.style.display= 'none' ;
        dueDateEditBtn.style.display = 'none' ;
        newdueDate.style.display = 'inline-block' ;
    }

    function saveNewDueDate() {
        var  dueDateContent = getEleById('dueDate-content');
        var  dueDateEditBtn = getEleById('dueDate-editBtn');
        var  newdueDate = getEleById('newDueDate');

        dueDateContent.style.display= 'inline-block'  ;
        dueDateEditBtn.style.display = 'inline-block';
        newdueDate.style.display =  'none';



        var dueDateInput = getEleById('dueDateInput');
        var deuDateContent = getEleById('dueDate-content');
        var newDate = dueDateInput.innerText;
        deuDateContent.innerText = newDate ;

        // infoModel.createtime = newDate;
        infoModel.userid = userID;
        infoModel.institutionid = null ;
        updateCompanyInfo(infoModel);
    }


    /**
     * 修改状态  正常1 禁用0
     */

    function editStatus() {
        var  statusContent = getEleById('status-content');
        var  statusditBtn = getEleById('status-editBtn');
        var  newstatus = getEleById('newStatus');

        statusContent.style.display= 'none' ;
        statusditBtn.style.display = 'none' ;
        newstatus.style.display = 'inline-block' ;
    }
    function selectStatus() {

    }

    function saveStatus() {
        var  statusContent = getEleById('status-content');
        var  statusditBtn = getEleById('status-editBtn');
        var  newstatus = getEleById('newStatus');

        statusContent.style.display= 'inline-block'  ;
        statusditBtn.style.display = 'inline-block';
        newstatus.style.display =  'none';

        var statusSelect = getEleById('statusSelect');
        var status = getEleById('status-content');
        var statusName = statusSelect.options[statusSelect.selectedIndex].innerText;
        status.innerText = statusName ;
        if (statusName == '正常'){
            infoModel.userstatus = '1';
        }else {
            infoModel.userstatus = '0';
        }

        infoModel.userid = userID;
        infoModel.institutionid = null ;
        updateCompanyInfo(infoModel);
    }


    function showIndustryL1(industry1) {
        var len = industry1.length;
        for (var i = 0; i < len; i++) {
            var industryOpt = document.createElement('option');
            industryOpt.innerText = industry1[i]['name'];
            industryOpt.value = industry1[i]['code'];
            industryL1.appendChild(industryOpt);
        }
    }
    function selectIndustryL1() {

        var industrtyCode = industryL1.options[industryL1.selectedIndex].value;
        var industryName = industryL1.options[industryL1.selectedIndex].innerText;
        infoModel.industrycode1 = industrtyCode;
        infoModel.industryname1 = industryName;
        getIndustryWithCode(industrtyCode,2);
    }


    function showIndustryL2(industry2) {
        industryL2.options.length = 0 ;
        var selectOpt = document.createElement('option');
        selectOpt.innerText = '--请选择--';
        selectOpt.value = null ;
        industryL2.appendChild(selectOpt);
        var len = industry2.length;
        for (var i = 0; i < len; i++) {
            var industryOpt = document.createElement('option');
            industryOpt.innerText = industry2[i]['name'];
            industryOpt.value = industry2[i]['code'];
            industryL2.appendChild(industryOpt);
        }
    }
    function selectIndustryL2() {

        var industrtyCode = industryL2.options[industryL2.selectedIndex].value;
        var industryName = industryL2.options[industryL2.selectedIndex].innerText;
        infoModel.industrycode2 = industrtyCode;
        infoModel.industryname2 = industryName;
        getIndustryWithCode(industrtyCode,3);
    }

    function showIndustryL3(industry3) {
        industryL3.options.length = 0 ;
        var selectOpt = document.createElement('option');
        selectOpt.innerText = '--请选择--';
        selectOpt.value = null ;
        industryL3.appendChild(selectOpt);
        var len = industry3.length;
        for (var i = 0; i < len; i++) {
            var industryOpt = document.createElement('option');
            industryOpt.innerText = industry3[i]['name'];
            industryOpt.value = industry3[i]['code'];
            industryL3.appendChild(industryOpt);
        }
    }
    function selectIndustryL3() {

        var industrtyCode = industryL3.options[industryL3.selectedIndex].value;
        var industryName = industryL3.options[industryL3.selectedIndex].innerText;
        infoModel.industrycode3 = industrtyCode;
        infoModel.industryname3 = industryName;
        getIndustryWithCode(industrtyCode,4);
    }
    function showIndustryL4(industry4) {
        industryL4.options.length = 0 ;
        var selectOpt = document.createElement('option');
        selectOpt.innerText = '--请选择--';
        selectOpt.value = null ;
        industryL4.appendChild(selectOpt);
        var len = industry4.length;
        for (var i = 0; i < len; i++) {
            var industryOpt = document.createElement('option');
            industryOpt.innerText = industry4[i]['name'];
            industryOpt.value = industry4[i]['code'];
            industryL4.appendChild(industryOpt);
        }
    }
    function selectIndustryL4() {

        var industrtyCode = industryL4.options[industryL4.selectedIndex].value;
        var industryName = industryL4.options[industryL4.selectedIndex].innerText;
        infoModel.industrycode4 = industrtyCode;
        infoModel.industryname4 = industryName;
    }






    // var addrShow = $('addr-show');
    // var btn = document.getElementsByClassName('met1')[0];
    var prov = getEleById('prov');
    var city = getEleById('city');
    var country = getEleById('country');

    var industryL1 = getEleById('industryL1');
    var industryL2 = getEleById('industryL2');
    var industryL3 = getEleById('industryL3');
    var industryL4 = getEleById('industryL4');


    /*用于保存当前所选的省市区*/
    var current = {
        prov: '',
        city: '',
        country: ''
    };

    /*点击区域编辑按钮的时候自动获取省份列表  此处可以自动显示省份列表*/
    function showProvince(provinceList) {
        // btn.disabled = true;

        console.log('显示省份列表');

        var len = provinceList.length;
        for (var i = 0; i < len; i++) {
            var provOpt = document.createElement('option');
            provOpt.innerText = provinceList[i]['areaname'];
            provOpt.value = provinceList[i]['areacode'];
            prov.appendChild(provOpt);
        }
    };
    //选择完省份 去网络获取城市列表
    function selectProvince() {


        var provinceCode = prov.options[prov.selectedIndex].value;
        var provinceName = prov.options[prov.selectedIndex].innerText;
        infoModel.provincecode = provinceCode;
        infoModel.province = provinceName;

        if (provinceName != current.prov){
            current.prov = provinceName;
        }
        getRegionWithCode(provinceCode,2);
    }


    /*网络获取完城市列表  根据所选的省份来显示城市列表*/
    function showCity(cityList) {

        city.options.length = 0 ;
        var selectOpt = document.createElement('option');
        selectOpt.innerText = '--请选择--';
        selectOpt.value = null ;
        city.appendChild(selectOpt);
        for (var j = 0; j < cityList.length; j++) {
            var cityOpt = document.createElement('option');
            cityOpt.innerText = cityList[j]['areaname'];
            cityOpt.value = cityList[j]['areacode'];
            city.appendChild(cityOpt);
        }
    }

    //城市选择完成后 去获取区县的列表
    function selectCity() {

        console.log(city.selectedIndex);
        var cityCode = city.options[city.selectedIndex].value;
        var cityName = city.options[city.selectedIndex].innerText;
        infoModel.citycode = cityCode;
        infoModel.city = cityName;

        if (cityName != current.city){
            current.city = cityName;
        }
        getRegionWithCode(cityCode,3);
    }


    /*网络获取完区县后  根据所选的城市来显示县区列表*/
    function showCountry(countryList) {
        console.log(countryList);

        country.options.length = 0 ;
        var selectOpt = document.createElement('option');
        selectOpt.innerText = '--请选择--';
        selectOpt.value = null;
        country.appendChild(selectOpt);


        for (var n = 0; n < countryList.length; n++) {
            var countryOpt = document.createElement('option');
            countryOpt.innerText = countryList[n]['areaname'];
            countryOpt.value = countryList[n]['areacode'];
            country.appendChild(countryOpt);
        }
        console.log('country.options:======='+ country.options);
    }

    //
    /*选择县区*/
    function selecCountry() {
        var countryCode = country.options[country.selectedIndex].value;
        var countryName = country.options[country.selectedIndex].innerText;
        infoModel.districtcode = countryCode;
        infoModel.district = countryName;
        if (countryName != current.country){
            current.country = countryName;
        }
    }

    function getRegionWithCode(parentCode ,level) {

        var  url = '/tax/getAreaData/' + parentCode;
        var config = {
            url: 'http://localhost:8088'+url,
            type: 'get',
            success: function(result) {
                console.log(result);
                if (level==1){
                    showProvince(result);
                } else if(level == 2){
                    showCity(result);
                }else if (level ==3){
                    showCountry(result);
                } else {

                }
            }
        };
        console.log(config);
        $.ajax(config);

    }

    function getIndustryWithCode(parentCode ,level) {

        var  url = '/tax/getIndustry/' + parentCode;
        var config = {
            url: 'http://localhost:8088'+url,
            type: 'get',
            success: function(result) {
                console.log(result);
                if (level==1){
                    showIndustryL1(result);
                } else if(level == 2){
                    showIndustryL2(result);
                }else if (level ==3){
                    showIndustryL3(result);
                }else if (level ==4){
                    showIndustryL4(result);
                }
                else {

                }
            }
        };
        console.log(config);
        $.ajax(config);

    }


    function updateCompanyInfo( infoModel) {

        var  url = '/tax/update';
        console.log("kakakakkakakaka");

        console.log(infoModel);
        if (infoModel.userstatus == '正常'){
            infoModel.userstatus = '1';
        }else  if (infoModel.userstatus == '禁用'){
            infoModel.userstatus = '0';
        }

        var config = {
            url: 'http://localhost:8088'+url,
            type: 'post',
            data:infoModel
,            success: function(result) {
                console.log(result);

            }
        };
        console.log(config);
        $.ajax(config);
    }



</script>
</body>
</html>
